# -*- coding: utf-8 -*-

# Define here the models for your scraped items
#
# See documentation in:
# https://doc.scrapy.org/en/latest/topics/items.html

import scrapy


class KaolaItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()

    openid = scrapy.Field()
    article = scrapy.Field()
    follower = scrapy.Field()
    following = scrapy.Field()
    liked = scrapy.Field()
    blackcard = scrapy.Field()
    gender = scrapy.Field()
    personalStatus = scrapy.Field()
    nickName = scrapy.Field()
    profilePhoto = scrapy.Field()
    jumpUrl = scrapy.Field()
    verifyDesc = scrapy.Field()

    def save_to_mysql(self):

        sql = 'insert into kaola_user_info(openid,article,follower,following,liked,blackcard,gender,personalStatus,nickName,profilePhoto,jumpUrl,verifyDesc)' \
              'values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'

        data = (self["openid"],self["article"],self["follower"],self["following"],self["liked"],self["blackcard"],self["gender"],self["personalStatus"],self["nickName"],self["profilePhoto"],self["jumpUrl"],self["verifyDesc"])

        return sql,data


class KaolaArticleItem(scrapy.Item):

    openid_userid = scrapy.Field()
    article_id = scrapy.Field()
    article_info_url = scrapy.Field()
    commentNum = scrapy.Field()
    descs = scrapy.Field()
    favorNum = scrapy.Field()
    title = scrapy.Field()
    publishTime = scrapy.Field()

    def save_to_mysql(self):

        sql = 'insert into kaola_article_info(openid_userid,article_id,article_info_url,commentNum,descs,favorNum,title,publishTime)' \
              'values (%s,%s,%s,%s,%s,%s,%s,%s)'

        data = (self["openid_userid"],self["article_id"],self["article_info_url"],self["commentNum"],self["descs"],self["favorNum"],self["title"],self["publishTime"])

        return sql,data